require("GYJSPatchTextViewController,UILabel,UIColor,UIScreen,CGGeometry,UIView,UIImageView,UIImage,UITextField,UIFont,UITapGestureRecognizer,UIActionSheet,NSArray,UIButton,UIBarButtonItem")

defineClass("GYJSPatchTextViewController : UIViewController<UIActionSheetDelegate>",["questionLabel","questionTitle","questionView","arrow","answer","answerView","answerTF","tip","confirm"] ,{
            
            viewDidLoad :function () {
                self.super().viewDidLoad()
                self.setTitle("设置交易密码")
                self.setUp()
            },
            
            setUp : function() {
            
                var screenWidth = UIScreen.mainScreen().bounds().width
                var screenHeight = UIScreen.mainScreen().bounds().height
                var  topEdge = 10
            
                questionLabel = UILabel.alloc().initWithFrame({x:10,y:80,width:200,height:20})
                questionLabel.setText("问题")
                self.view().addSubview(questionLabel)
            
                var questionViewY = questionLabel.frame().y + questionLabel.frame().height + topEdge
                questionView = UIView.alloc().initWithFrame({x:0,y:questionViewY,width:screenWidth,height:30})
                questionView.setBackgroundColor(UIColor.whiteColor())
                self.view().addSubview(questionView)
            
                var tap = UITapGestureRecognizer.alloc().initWithTarget_action(self,"tapClick")
                questionView.userInteractionEnabled = YES
                questionView.addGestureRecognizer(tap)
            
                questionTitle = UILabel.alloc().initWithFrame({x:10,y:0,width:screenWidth-10,height:30})
                questionTitle.setBackgroundColor(UIColor.clearColor())
                questionTitle.setText("您的宠物名字是?")
                questionView.addSubview(questionTitle)
            
            
                arrow = UIImageView.alloc().initWithFrame({x:screenWidth - 30,y:5,width:20,height:20})
                arrow.setImage(UIImage.imageNamed("gyhe_arrow_blue"))
                questionView.addSubview(arrow)
            
                var answerY = questionView.frame().y + questionView.frame().height + topEdge
                answer = UILabel.alloc().initWithFrame({x:questionTitle.frame().x,y:answerY,width:200,height:questionLabel.frame().height})
                answer.setText("答案")
                self.view().addSubview(answer)
            
            
                var answerViewY  = answer.frame().y + answer.frame().height + topEdge
                answerView = UIView.alloc().initWithFrame({x:0,y:answerViewY,width:screenWidth,height:questionView.frame().height})
                answerView.setBackgroundColor(UIColor.whiteColor())
                self.view().addSubview(answerView)
            
                var answerTFY = answer.frame().y + answer.frame().height + topEdge
                answerTF = UITextField.alloc().initWithFrame({x:questionTitle.frame().x,y:0,width:screenWidth -questionTitle.frame().x,height:questionTitle.frame().height})
                answerTF.setPlaceholder("输入密码")
                answerView.addSubview(answerTF)
            
                var tipY = answerView.frame().y + answerView.frame().height + topEdge
                tip = UILabel.alloc().initWithFrame({x:questionLabel.frame().x,y:tipY,width:screenWidth -questionLabel.frame().x,height:questionLabel.frame().height})
                tip.setText("提示：密码问题是用于登录密码找回的一种方式，一旦您设置了密码提问，请一定牢记.")
                tip.setNumberOfLines(0)
                tip.setFont(UIFont.systemFontOfSize(12))
                self.view().addSubview(tip)
                var size = self.sizeWithWidth_AndLabel(tip.frame().width,tip)
                tip.setFrame({x:tip.origin().x,y:tip.origin().y,width:size.width,height:size.height})
            
            
                confirm = UIButton.buttonWithType(0)
                confirm.setFrame({x:0,y:0,width:50,height:25})
                confirm.setTitle_forState("确定",0)
                confirm.setTitleColor_forState(UIColor.redColor(),0)
                confirm.addTarget_action_forControlEvents(self,"btnClick",1<<6)
                self.navigationItem().setRightBarButtonItem(UIBarButtonItem.alloc().initWithCustomView(confirm))
            
            
            },
            
            sizeWithWidth_AndLabel :function (width,label) {
                label.setLineBreakMode(1)
                var size = label.sizeThatFits({width:width,height:10000})
                return size
            },
            
            tapClick : function() {
            
                console.log("tapClick")
                var sheet = UIActionSheet.alloc().initWithTitle_delegate_cancelButtonTitle_destructiveButtonTitle_otherButtonTitles(null,self,"取消",null,"您的宠物名字是?","您的幸运数字是?","您的喜欢的人是?", null)
                sheet.showInView(self.view)
            },
            
            actionSheet_clickedButtonAtIndex :function(actionSheet,buttonIndex) {
                console.log(buttonIndex)
                var data = ["您的宠物名字是?","您的幸运数字是?","您的喜欢的人是?"]
                if(buttonIndex < 3) {
                    questionTitle.setText(data[buttonIndex])
                }
            
            },
            
            btnClick : function() {
            
                console.log(questionTitle.text(),answerTF.text())
            }
            
            
})




